package service

import (
	"gitee.com/gopher2011/litemall/app/dao"
	"time"
)

// 广告 /admin/ad
var Advertise = advertiseService{}

// 广告
// 私有对象，所有的方法都绑定到这个结构体上。
type advertiseService struct{}

// 添加 /create Post 参数:
func (p *advertiseService) Create(arg dao.Advertise) (int64, error) {
	arg.AddTime = time.Now()
	arg.UpdateTime = time.Now()
	return dao.AdvertiseDao.InsertTemplate(arg)
}

func (p *advertiseService) Delete(id int64) (int64, error) {
	return dao.AdvertiseDao.DeleteTemplate(id)
}

func (p *advertiseService) Update(arg dao.Advertise) (int64, error) {
	arg.UpdateTime = time.Now()
	return dao.AdvertiseDao.UpdateTemplate(arg)
}

// 分页查询 /list  Get 参数 sort,order,page,limit
func (p *advertiseService) List(arg dao.AdvertiseList) ([]dao.Advertise, error) {
	arg.PageNum = (arg.PageNum - 1) * arg.PageSize
	return dao.AdvertiseDao.List(arg)
}

func (p *advertiseService) GetItem(id int64) (dao.Advertise, error) {
	return dao.AdvertiseDao.SelectTemplate(id)
}
